<?php
//Include Common Files @1-020C101F
define("RelativePath", ".");
define("PathToCurrentPage", "/");
define("FileName", "cardescr.php");
include(RelativePath . "/Common.php");
include(RelativePath . "/Template.php");
include(RelativePath . "/Sorter.php");
include(RelativePath . "/Navigator.php");
//End Include Common Files

//Include Page implementation @43-3DD2EFDC
include_once(RelativePath . "/Header.php");
//End Include Page implementation

class clsGridcar { //car class @2-D4BC9732

//Variables @2-C23F2C5F

    // Public variables
    var $ComponentType = "Grid";
    var $ComponentName;
    var $Visible;
    var $Errors;
    var $ErrorBlock;
    var $ds;
    var $DataSource;
    var $PageSize;
    var $SorterName = "";
    var $SorterDirection = "";
    var $PageNumber;

    var $CCSEvents = "";
    var $CCSEventResult;

    var $RelativePath = "";

    // Grid Controls
    var $StaticControls;
    var $RowControls;
//End Variables

//Class_Initialize Event @2-2372DE11
    function clsGridcar($RelativePath, & $Parent)
    {
        global $FileName;
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->ComponentName = "car";
        $this->Visible = True;
        $this->Parent = & $Parent;
        $this->RelativePath = $RelativePath;
        $this->Errors = new clsErrors();
        $this->ErrorBlock = "Grid car";
        $this->DataSource = new clscarDataSource($this);
        $this->ds = & $this->DataSource;
        $this->PageSize = CCGetParam($this->ComponentName . "PageSize", "");
        if(!is_numeric($this->PageSize) || !strlen($this->PageSize))
            $this->PageSize = 20;
        else
            $this->PageSize = intval($this->PageSize);
        if ($this->PageSize > 100)
            $this->PageSize = 100;
        if($this->PageSize == 0)
            $this->Errors->addError("<p>Form: Grid " . $this->ComponentName . "<br>Error: (CCS06) Invalid page size.</p>");
        $this->PageNumber = intval(CCGetParam($this->ComponentName . "Page", 1));
        if ($this->PageNumber <= 0) $this->PageNumber = 1;

        $this->Brand = & new clsControl(ccsLabel, "Brand", "Brand", ccsText, "", CCGetRequestParam("Brand", ccsGet), $this);
        $this->Model = & new clsControl(ccsLabel, "Model", "Model", ccsText, "", CCGetRequestParam("Model", ccsGet), $this);
        $this->CC = & new clsControl(ccsLabel, "CC", "CC", ccsInteger, "", CCGetRequestParam("CC", ccsGet), $this);
        $this->Doors = & new clsControl(ccsLabel, "Doors", "Doors", ccsInteger, "", CCGetRequestParam("Doors", ccsGet), $this);
        $this->Persons = & new clsControl(ccsLabel, "Persons", "Persons", ccsInteger, "", CCGetRequestParam("Persons", ccsGet), $this);
        $this->AC = & new clsControl(ccsLabel, "AC", "AC", ccsInteger, "", CCGetRequestParam("AC", ccsGet), $this);
        $this->Airbag = & new clsControl(ccsLabel, "Airbag", "Airbag", ccsInteger, "", CCGetRequestParam("Airbag", ccsGet), $this);
        $this->Fuel = & new clsControl(ccsLabel, "Fuel", "Fuel", ccsText, "", CCGetRequestParam("Fuel", ccsGet), $this);
        $this->Gear = & new clsControl(ccsLabel, "Gear", "Gear", ccsText, "", CCGetRequestParam("Gear", ccsGet), $this);
        $this->Free = & new clsControl(ccsLabel, "Free", "Free", ccsInteger, "", CCGetRequestParam("Free", ccsGet), $this);
        $this->Image1 = & new clsControl(ccsImage, "Image1", "Image1", ccsText, "", CCGetRequestParam("Image1", ccsGet), $this);
    }
//End Class_Initialize Event

//Initialize Method @2-90E704C5
    function Initialize()
    {
        if(!$this->Visible) return;

        $this->DataSource->PageSize = & $this->PageSize;
        $this->DataSource->AbsolutePage = & $this->PageNumber;
        $this->DataSource->SetOrder($this->SorterName, $this->SorterDirection);
    }
//End Initialize Method

//Show Method @2-058A09CA
    function Show()
    {
        global $Tpl;
        global $CCSLocales;
        if(!$this->Visible) return;

        $ShownRecords = 0;

        $this->DataSource->Parameters["urlModel"] = CCGetFromGet("Model", "");

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeSelect", $this);


        $this->DataSource->Prepare();
        $this->DataSource->Open();

        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShow", $this);
        if(!$this->Visible) return;

        $GridBlock = "Grid " . $this->ComponentName;
        $ParentPath = $Tpl->block_path;
        $Tpl->block_path = $ParentPath . "/" . $GridBlock;


        if(($ShownRecords < $this->PageSize) && $this->DataSource->next_record())
        {
            do {
                $this->DataSource->SetValues();
                $Tpl->block_path = $ParentPath . "/" . $GridBlock . "/Row";
                $this->Brand->SetValue($this->DataSource->Brand->GetValue());
                $this->Model->SetValue($this->DataSource->Model->GetValue());
                $this->CC->SetValue($this->DataSource->CC->GetValue());
                $this->Doors->SetValue($this->DataSource->Doors->GetValue());
                $this->Persons->SetValue($this->DataSource->Persons->GetValue());
                $this->AC->SetValue($this->DataSource->AC->GetValue());
                $this->Airbag->SetValue($this->DataSource->Airbag->GetValue());
                $this->Fuel->SetValue($this->DataSource->Fuel->GetValue());
                $this->Gear->SetValue($this->DataSource->Gear->GetValue());
                $this->Free->SetValue($this->DataSource->Free->GetValue());
                $this->Image1->SetValue($this->DataSource->Image1->GetValue());
                $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeShowRow", $this);
                $this->Brand->Show();
                $this->Model->Show();
                $this->CC->Show();
                $this->Doors->Show();
                $this->Persons->Show();
                $this->AC->Show();
                $this->Airbag->Show();
                $this->Fuel->Show();
                $this->Gear->Show();
                $this->Free->Show();
                $this->Image1->Show();
                $Tpl->block_path = $ParentPath . "/" . $GridBlock;
                $Tpl->parse("Row", true);
                $ShownRecords++;
            } while (($ShownRecords < $this->PageSize) && $this->DataSource->next_record());
        }
        else // Show NoRecords block if no records are found
        {
            $Tpl->parse("NoRecords", false);
        }

        $errors = $this->GetErrors();
        if(strlen($errors))
        {
            $Tpl->replaceblock("", $errors);
            $Tpl->block_path = $ParentPath;
            return;
        }
        $Tpl->parse();
        $Tpl->block_path = $ParentPath;
        $this->DataSource->close();
    }
//End Show Method

//GetErrors Method @2-39F8DF22
    function GetErrors()
    {
        $errors = "";
        $errors = ComposeStrings($errors, $this->Brand->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Model->Errors->ToString());
        $errors = ComposeStrings($errors, $this->CC->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Doors->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Persons->Errors->ToString());
        $errors = ComposeStrings($errors, $this->AC->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Airbag->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Fuel->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Gear->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Free->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Image1->Errors->ToString());
        $errors = ComposeStrings($errors, $this->Errors->ToString());
        $errors = ComposeStrings($errors, $this->DataSource->Errors->ToString());
        return $errors;
    }
//End GetErrors Method

} //End car Class @2-FCB6E20C

class clscarDataSource extends clsDBConnection1 {  //carDataSource Class @2-E8FA35FB

//DataSource Variables @2-94D58449
    var $Parent = "";
    var $CCSEvents = "";
    var $CCSEventResult;
    var $ErrorBlock;
    var $CmdExecution;

    var $CountSQL;
    var $wp;


    // Datasource fields
    var $Brand;
    var $Model;
    var $CC;
    var $Doors;
    var $Persons;
    var $AC;
    var $Airbag;
    var $Fuel;
    var $Gear;
    var $Free;
    var $Image1;
//End DataSource Variables

//DataSourceClass_Initialize Event @2-545E03D6
    function clscarDataSource(& $Parent)
    {
        $this->Parent = & $Parent;
        $this->ErrorBlock = "Grid car";
        $this->Initialize();
        $this->Brand = new clsField("Brand", ccsText, "");
        $this->Model = new clsField("Model", ccsText, "");
        $this->CC = new clsField("CC", ccsInteger, "");
        $this->Doors = new clsField("Doors", ccsInteger, "");
        $this->Persons = new clsField("Persons", ccsInteger, "");
        $this->AC = new clsField("AC", ccsInteger, "");
        $this->Airbag = new clsField("Airbag", ccsInteger, "");
        $this->Fuel = new clsField("Fuel", ccsText, "");
        $this->Gear = new clsField("Gear", ccsText, "");
        $this->Free = new clsField("Free", ccsInteger, "");
        $this->Image1 = new clsField("Image1", ccsText, "");

    }
//End DataSourceClass_Initialize Event

//SetOrder Method @2-B03AEEC3
    function SetOrder($SorterName, $SorterDirection)
    {
        $this->Order = "Brand";
        $this->Order = CCGetOrder($this->Order, $SorterName, $SorterDirection, 
            "");
    }
//End SetOrder Method

//Prepare Method @2-0C6FD93E
    function Prepare()
    {
        global $CCSLocales;
        global $DefaultDateFormat;
        $this->wp = new clsSQLParameters($this->ErrorBlock);
        $this->wp->AddParameter("1", "urlModel", ccsText, "", "", $this->Parameters["urlModel"], "", false);
        $this->wp->Criterion[1] = $this->wp->Operation(opEqual, "Model", $this->wp->GetDBValue("1"), $this->ToSQL($this->wp->GetDBValue("1"), ccsText),false);
        $this->Where = 
             $this->wp->Criterion[1];
    }
//End Prepare Method

//Open Method @2-7EB7CECF
    function Open()
    {
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeBuildSelect", $this->Parent);
        $this->CountSQL = "SELECT COUNT(*) " .
        "FROM car";
        $this->SQL = "SELECT car.id, car.Brand, car.Model, car.CC, car.Doors, car.Persons, car.AC, car.Airbag, car.Fuel, car.Gear, car.Free, car.iconame  " .
        "FROM car {SQL_Where} {SQL_OrderBy}";
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeExecuteSelect", $this->Parent);
        if ($this->CountSQL) 
            $this->RecordsCount = CCGetDBValue(CCBuildSQL($this->CountSQL, $this->Where, ""), $this);
        else
            $this->RecordsCount = "CCS not counted";
        $this->query($this->OptimizeSQL(CCBuildSQL($this->SQL, $this->Where, $this->Order)));
        $this->CCSEventResult = CCGetEvent($this->CCSEvents, "AfterExecuteSelect", $this->Parent);
    }
//End Open Method

//SetValues Method @2-51398556
    function SetValues()
    {
        $this->Brand->SetDBValue($this->f("Brand"));
        $this->Model->SetDBValue($this->f("Model"));
        $this->CC->SetDBValue(trim($this->f("CC")));
        $this->Doors->SetDBValue(trim($this->f("Doors")));
        $this->Persons->SetDBValue(trim($this->f("Persons")));
        $this->AC->SetDBValue(trim($this->f("AC")));
        $this->Airbag->SetDBValue(trim($this->f("Airbag")));
        $this->Fuel->SetDBValue($this->f("Fuel"));
        $this->Gear->SetDBValue($this->f("Gear"));
        $this->Free->SetDBValue(trim($this->f("Free")));
        $this->Image1->SetDBValue($this->f("iconame"));
    }
//End SetValues Method

} //End carDataSource Class @2-FCB6E20C

//Include Page implementation @44-58DBA1E3
include_once(RelativePath . "/Footer.php");
//End Include Page implementation

//Initialize Page @1-C27A854F
// Variables
$FileName = "";
$Redirect = "";
$Tpl = "";
$TemplateFileName = "";
$BlockToParse = "";
$ComponentName = "";

// Events;
$CCSEvents = "";
$CCSEventResult = "";

$FileName = FileName;
$Redirect = "";
$TemplateFileName = "cardescr.html";
$BlockToParse = "main";
$TemplateEncoding = "UTF-8";
$PathToRoot = "./";
//End Initialize Page

//Initialize Objects @1-F3FDACB0
$DBConnection1 = new clsDBConnection1();
$MainPage->Connections["Connection1"] = & $DBConnection1;

// Controls
$Header = & new clsHeader("", "Header", $MainPage);
$Header->Initialize();
$car = & new clsGridcar("", $MainPage);
$Footer = & new clsFooter("", "Footer", $MainPage);
$Footer->Initialize();
$MainPage->Header = & $Header;
$MainPage->car = & $car;
$MainPage->Footer = & $Footer;
$car->Initialize();

$CCSEventResult = CCGetEvent($CCSEvents, "AfterInitialize", $MainPage);

$Charset = $Charset ? $Charset : "utf-8";
if ($Charset)
    header("Content-Type: text/html; charset=" . $Charset);
//End Initialize Objects

//Initialize HTML Template @1-78E0DC24
$CCSEventResult = CCGetEvent($CCSEvents, "OnInitializeView", $MainPage);
$Tpl = new clsTemplate($FileEncoding, $TemplateEncoding);
$Tpl->LoadTemplate(PathToCurrentPage . $TemplateFileName, $BlockToParse, "UTF-8");
$Tpl->block_path = "/$BlockToParse";
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeShow", $MainPage);
//End Initialize HTML Template

//Execute Components @1-351F985C
$Header->Operations();
$Footer->Operations();
//End Execute Components

//Go to destination page @1-6EC7D9ED
if($Redirect)
{
    $CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
    $DBConnection1->close();
    header("Location: " . $Redirect);
    $Header->Class_Terminate();
    unset($Header);
    unset($car);
    $Footer->Class_Terminate();
    unset($Footer);
    unset($Tpl);
    exit;
}
//End Go to destination page

//Show Page @1-8D3C3859
$Header->Show();
$car->Show();
$Footer->Show();
$Tpl->block_path = "";
$Tpl->Parse($BlockToParse, false);
$main_block = $Tpl->GetVar($BlockToParse);
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeOutput", $MainPage);
if ($CCSEventResult) echo $main_block;
//End Show Page

//Unload Page @1-3B1B3321
$CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
$DBConnection1->close();
$Header->Class_Terminate();
unset($Header);
unset($car);
$Footer->Class_Terminate();
unset($Footer);
unset($Tpl);
//End Unload Page


?>
